import pagination from '@/views/pagination'  //分页组件
import suppleDialogForm from '@/views/BasicDataMNG/distributor/suppleDialogForm'
import basicDialogForm from '@/views/BasicDataMNG/distributor/basicDialogForm'      //之前的编辑组件
import agentHttp from '@/utils/agentHttp.js'
import {debounce} from '@/utils/index.js'
import {confirm} from '@/utils/confirm'      //二次确认组件
import exportExcel from '@/utils/exportExcel' //导出

//更改需求后，实际引用的组件，前面的组件还不能删，不知道在哪引用了 ， 垃圾代码；
import authDialogForm from './authDialogForm'   //企业认证及查看组件
import editPopup from './editPopup.vue'    // 编辑组件
import oneselfProve from './oneselfProve.vue'    // 实名认证组件

export default {
  name: 'vehicleFollow',
  components: {
    pagination,authDialogForm,suppleDialogForm,basicDialogForm,editPopup,oneselfProve
  },
  created() {
  this.seachData(this.searchForm);
  this.getStatusMap();
  },
  data() {
    return {
      //搜索字段
      searchForm: {
        name:"",
        person:"",
        phone:"",
        startDate:"",
        endDate:"",
        source:"",
        enable:"",
        searchCity:"",
        realNameAuthStartDate:"",
        realNameAuthEndDate:"",
        realNameIsData:"",
        authStartDate:"",
        authEndDate:"",
        isData:"",
        status:"",
        realname:"",
        category:"",
        dealerCompanyName:"",
        type:'',

      },
      //表格字段
      tableData: [],
      //弹窗状态值
      authDialogFormVisible:{
        isAdd:"",
        dialogFormVisible:"",
        id:""
      },
      suppleDialogFormVisible:{
        isAdd:"",
        dialogFormVisible:"",
        dealerInfoId:"",
        id:""
      },
      basicDialogFormVisible:{
        isAdd:"",
        dialogFormVisible:"",
        id:""
      },
      oneselfProveFormVisible:{
        isAdd:"",
        dialogFormVisible:"",
        id:""
      },
      formLabelWidth: '120px',
      statusMap:'',
      dealerSource:'',
      dealerEnable:'',
      dealerData:'',
      type:'',
      category:"",
      startDateOpt: {
          disabledDate(time) {
            return time.getTime() > Date.now() 
          }
      },
      endDateOpt:{
          disabledDate:(time)=>{
            return time.getTime()< new Date(this.searchForm.startDate).getTime();
          }
      },
      resetFormStatus:false
    }
  },

  methods: {
  //查看所有
  seachData(){
      if(!this.resetFormStatus){
        var params=this.searchForm||{};
        params.page=this.tableData.page||1;
        params.rows=this.tableData.rows||10;
        agentHttp.postJson('adminApi/admin/dealer_ordinary/list?page='+params.page+'&rows='+params.rows,params ).then((data)=>{
              this.tableData = data
        })
      }
    },

    /*搜索按钮方法*/
    //搜索
     debounceSeach(){
      this.tableData.page=1;
      debounce(this.seachData(this.searchForm),1000)
     },
     //实名认证状态||企业认证状态单选
     deleteValue(value){
        if (value == 'realNameStatus'){
            this.searchForm.seniorStatus = ""
        } else if (value == 'seniorStatus') {
            this.searchForm.realNameStatus = ""
        }
     },

    //重置
    resetSearchForm(formName) {
      this.resetFormStatus=true;
      this.tableData.page=1;
      this.tableData.rows=10;
      this.$refs[formName].resetFields();
      this.$nextTick(_ =>{
        this.resetFormStatus=false;
        this.seachData();
      })
    },
    /*表格操作按钮*/
    //编辑基本资料
    handleBasic(row) {
      row?this.basicDialogFormVisible.id=row.id:this.basicDialogFormVisible.id=""; 
      this.basicDialogFormVisible.isAdd=true;
      this.basicDialogFormVisible.dialogFormVisible=true;
    },
    //编辑认证资料
    handleAuth(index, row, bool) {
      row?this.authDialogFormVisible.id=row.id:this.authDialogFormVisible.id=""; 
      this.authDialogFormVisible.isAdd=true;
      this.authDialogFormVisible.dialogFormVisible=true;
    },
    handleOneself(index, row, bool){
      row?this.oneselfProveFormVisible.id=row.id:this.authDialogFormVisible.id=""; 
      this.oneselfProveFormVisible.isAdd=true;
      this.oneselfProveFormVisible.dialogFormVisible=true;
    },
    handleSee(index, row, bool) {
      row?this.authDialogFormVisible.id=row.id:this.authDialogFormVisible.id=""; 
      this.authDialogFormVisible.isAdd=false;
      this.authDialogFormVisible.dialogFormVisible=true;
    },
    //编辑补充资料
    handleSupple(index, row ,bool) {
      row?this.suppleDialogFormVisible.id=row.id:this.suppleDialogFormVisible.id="";
      row?this.suppleDialogFormVisible.dealerInfoId=row.dealerInfoId:this.suppleDialogFormVisible.dealerInfoId="";
      this.suppleDialogFormVisible.isAdd=true;
      this.suppleDialogFormVisible.dialogFormVisible=true;
    },

    //停用按钮
    handleDisable(index, row) {
      if(!row.enable){
        var message="启用"
      }else{
        var message="停用"
      };
      this.$nextTick(()=>{
        confirm(()=>{
             agentHttp.put('adminApi/admin/dealer_ordinary/disable/'+row.id).then((data)=>{
              if(data.success){  
                //修改启用或者禁用
                  this.$message.success(data.data);
                  this.seachData({});
                  //这里编写数据赋值或者其他逻辑  例如：this.tableData = data;
              } 
            })  
          },()=>{
            this.$message.info("已取消"+message);
          },"确认"+message+"该条数据吗?");
      })
    },
    exportExcels(searchForm,url,name){
      exportExcel(searchForm,url,name)
    },
    
   getStatusMap(){
      agentHttp.get('adminApi/admin/dealer_ordinary/get_status_map' ).then((data)=>{
        this.dealerSource = data.data.dealerSource;
        this.dealerEnable = data.data.dealerEnable;
        this.dealerData = data.data.dealerData;
        this.statusMap=data.data.status;
        this.type=data.data.type;
        this.category = data.data.category ;

      })  
    },
    //时间空间方法
    pickerOptions0() {}
    /*send(){
      eventIsAdd.$emit('eventIsAdd', this.isAdd);
    }*/
  }
}